#include<bits/stdc++.h>
using namespace std;
const int N=1.5e6+5,mod=1e9+7;
int ksm(int a,int b=mod-2){int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)s=1ll*s*a%mod;
	return s;
}
int n,k,c,ans,d[N],sz[N];bool vis[N],use[N];
int head[N],cnt;struct node{int to,nxt;}e[N<<1];
void add(int u,int v){e[++cnt]={v,head[u]},head[u]=cnt;}
namespace init{int d[N],mx[N],p[N],mxn[N];
	void dfs(int u,int fa){
		for(int i=head[u],v;i;i=e[i].nxt)if((v=e[i].to)!=fa){
			d[v]=d[u]+1,dfs(v,u);
			int x=mx[v]+1;
			if(x>mx[u])mxn[u]=mx[u],p[u]=v,mx[u]=x;
			else if(x>mxn[u])mxn[u]=x;
		}
	}
	void dfs2(int u,int fa,int x){
		if(x>mx[u])mxn[u]=mx[u],p[u]=fa,mx[u]=x;
		else if(x>mxn[u])mxn[u]=x;
		if(mx[u]+mxn[u]<k-1)vis[u]=1,c++;
		for(int i=head[u],v;i;i=e[i].nxt)if((v=e[i].to)!=fa){
			int x=(p[u]==v?mxn[u]:mx[u])+1;
			dfs2(v,u,x);
		}
	} 
	void work(){
		dfs(1,0),dfs2(1,0,0);		
	}
} 
void dfs(int u,int fa,int d){
	if(d%k==0){
		if(!use[u])use[u]=1,dfs(u,0,0);
	}
	for(int i=head[u],v;i;i=e[i].nxt)if((v=e[i].to)!=fa)dfs(v,u,d+1);
}
bool check(int u,int fa,int d,int x){
	if(d==k-1&&(!x||x>1))return 0;
	for(int i=head[u],v;i;i=e[i].nxt)if((v=e[i].to)!=fa){
		if(!check(v,u,d+1,x+use[v]))return 0;
	}
	return 1;
}
void solve(int u){
	dfs(u,0,0);
	bool p=1;
	for(int i=1;i<=n;i++)p&=check(i,0,0,use[i]);
	if(p)ans++;
	for(int i=1;i<=n;i++)vis[i]|=use[i],use[i]=0;
} 
int main(){
	freopen("life.in","r",stdin);
	freopen("life.out","w",stdout);
	scanf("%d%d",&n,&k);
	if(n>10000){puts("YES");
		if(n<k)printf("%d\n",ksm(2,n));
		else printf("%d\n",k);
		return 0;
	}
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	init::work(); 
	for(int i=1;i<=n;i++)if(!vis[i])solve(i);
	if(ans)printf("YES\n%d\n",1ll*ans*ksm(2,c)%mod);
	else puts("NO\n0");
	return 0;
}

